8 * Need the CacheManager to be loaded
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
17 * Class representing a MediaWiki article and history.
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
42 * Constructor and clear the article
43 * @param mixed &$title
45 function Article( &$title ) {
46 $this->mTitle
=& $title;
51 * get the title object of the article
63 $this->mDataLoaded
= false;
64 $this->mContentLoaded
= false;
66 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
67 $this->mRedirectedFrom
= $this->mUserText
=
68 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
69 $this->mGoodAdjustment
= $this->mTotalAdjustment
= 0;
70 $this->mTouched
= '19700101000000';
71 $this->mForUpdate
= false;
72 $this->mIsRedirect
= false;
73 $this->mRevIdFetched
= 0;
77 * Note that getContent/loadContent may follow redirects if
78 * not told otherwise, and so may cause a change to mTitle.
81 * @return Return the text of this revision
83 function getContent( $noredir ) {
84 global $wgRequest, $wgUser, $wgOut;
86 # Get variables from query string :P
87 $action = $wgRequest->getText( 'action', 'view' );
88 $section = $wgRequest->getText( 'section' );
89 $preload = $wgRequest->getText( 'preload' );
91 $fname = 'Article::getContent';
92 wfProfileIn( $fname );
94 if ( 0 == $this->getID() ) {
95 if ( 'edit' == $action ) {
96 wfProfileOut( $fname );
98 # If requested, preload some text.
99 $text=$this->getPreloadedText($preload);
101 # We used to put MediaWiki:Newarticletext here if
102 # $text was empty at this point.
103 # This is now shown above the edit box instead.
106 wfProfileOut( $fname );
107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
108 return wfMsg( 'noarticletext' );
110 $this->loadContent( $noredir );
111 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
112 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
113 $wgUser->isIP($this->mTitle
->getText()) &&
116 wfProfileOut( $fname );
117 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
119 if($action=='edit') {
121 if($section=='new') {
122 wfProfileOut( $fname );
123 $text=$this->getPreloadedText($preload);
127 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
128 # comments to be stripped as well)
129 $rv=$this->getSection($this->mContent
,$section);
130 wfProfileOut( $fname );
134 wfProfileOut( $fname );
135 return $this->mContent
;
141 This function accepts a title string as parameter
142 ($preload). If this string is non-empty, it attempts
143 to fetch the current revision text.
145 function getPreloadedText($preload) {
147 $preloadTitle=Title
::newFromText($preload);
148 if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
149 $rev=Revision
::newFromTitle($preloadTitle);
151 return $rev->getText();
159 * This function returns the text of a section, specified by a number ($section).
160 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
161 * the first section before any such heading (section 0).
163 * If a section contains subsections, these are also returned.
165 * @param string $text text to look in
166 * @param integer $section section number
167 * @return string text of the requested section
169 function getSection($text,$section) {
171 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
172 # comments to be stripped as well)
174 $parser=new Parser();
175 $parser->mOutputType
=OT_WIKI
;
176 $parser->mOptions
= new ParserOptions();
177 $striptext=$parser->strip($text, $striparray, true);
179 # now that we can be sure that no pseudo-sections are in the source,
180 # split it up by section
183 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
185 PREG_SPLIT_DELIM_CAPTURE
);
189 $headline=$secs[$section*2-1];
190 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
193 # translate wiki heading into level
194 if(strpos($hlevel,'=')!==false) {
195 $hlevel=strlen($hlevel);
198 $rv=$headline. $secs[$section*2];
202 while(!empty($secs[$count*2-1]) && !$break) {
204 $subheadline=$secs[$count*2-1];
205 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
206 $subhlevel=$matches[1];
207 if(strpos($subhlevel,'=')!==false) {
208 $subhlevel=strlen($subhlevel);
210 if($subhlevel > $hlevel) {
211 $rv.=$subheadline.$secs[$count*2];
213 if($subhlevel <= $hlevel) {
220 # reinsert stripped tags
221 $rv=$parser->unstrip($rv,$striparray);
222 $rv=$parser->unstripNoWiki($rv,$striparray);
229 * Return an array of the columns of the "cur"-table
231 function getContentFields() {
232 return $wgArticleContentFields = array(
233 'old_text','old_flags',
234 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
235 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
239 * Return the oldid of the article that is to be shown.
240 * For requests with a "direction", this is not the oldid of the
243 function getOldID() {
244 global $wgRequest, $wgOut;
247 if ( isset( $lastid ) ) {
251 $oldid = $wgRequest->getVal( 'oldid' );
252 if ( isset( $oldid ) ) {
253 $oldid = intval( $oldid );
254 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
255 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
259 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
261 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
262 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
271 return @$oldid; # "@" to be able to return "unset" without PHP complaining
276 * Load the revision (including cur_text) into this object
278 function loadContent( $noredir = false ) {
279 global $wgOut, $wgRequest;
281 if ( $this->mContentLoaded
) return;
284 $oldid = $this->getOldID();
285 $redirect = $wgRequest->getVal( 'redirect' );
287 $fname = 'Article::loadContent';
289 # Pre-fill content with error message so that if something
290 # fails we'll have something telling us what we intended.
292 $t = $this->mTitle
->getPrefixedText();
294 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no')
295 ||
$wgRequest->getCheck( 'rdfrom' );
296 $this->mOldId
= $oldid;
297 $this->fetchContent( $oldid, $noredir, true );
302 * Fetch a page record with the given conditions
303 * @param Database $dbr
304 * @param array $conditions
307 function pageData( &$dbr, $conditions ) {
308 return $dbr->selectRow( 'page',
322 'Article::pageData' );
325 function pageDataFromTitle( &$dbr, $title ) {
326 return $this->pageData( $dbr, array(
327 'page_namespace' => $title->getNamespace(),
328 'page_title' => $title->getDBkey() ) );
331 function pageDataFromId( &$dbr, $id ) {
332 return $this->pageData( $dbr, array(
333 'page_id' => intval( $id ) ) );
337 * Set the general counter, title etc data loaded from
340 * @param object $data
343 function loadPageData( $data ) {
344 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
345 $this->mTitle
->mRestrictionsLoaded
= true;
347 $this->mCounter
= $data->page_counter
;
348 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
349 $this->mIsRedirect
= $data->page_is_redirect
;
350 $this->mLatest
= $data->page_latest
;
352 $this->mDataLoaded
= true;
356 * Get text of an article from database
357 * @param int $oldid 0 for whatever the latest revision is
358 * @param bool $noredir Set to false to follow redirects
359 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
362 function fetchContent( $oldid = 0, $noredir = true, $globalTitle = false ) {
363 if ( $this->mContentLoaded
) {
364 return $this->mContent
;
366 $dbr =& $this->getDB();
367 $fname = 'Article::fetchContent';
369 # Pre-fill content with error message so that if something
370 # fails we'll have something telling us what we intended.
371 $t = $this->mTitle
->getPrefixedText();
373 $t .= ',oldid='.$oldid;
375 if( isset( $redirect ) ) {
376 $redirect = ($redirect == 'no') ?
'no' : 'yes';
377 $t .= ',redirect='.$redirect;
379 $this->mContent
= wfMsg( 'missingarticle', $t );
382 $revision = Revision
::newFromId( $oldid );
383 if( is_null( $revision ) ) {
384 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
387 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
389 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
392 $this->mTitle
= Title
::makeTitle( $data->page_namespace
, $data->page_title
);
393 $this->loadPageData( $data );
395 if( !$this->mDataLoaded
) {
396 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
398 wfDebug( "$fname failed to find page data for title " . $this->mTitle
->getPrefixedText() . "\n" );
401 $this->loadPageData( $data );
403 $revision = Revision
::newFromId( $this->mLatest
);
404 if( is_null( $revision ) ) {
405 wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
410 # If we got a redirect, follow it (unless we've been told
411 # not to by either the function parameter or the query
412 if ( !$oldid && !$noredir ) {
413 $rt = Title
::newFromRedirect( $revision->getText() );
414 # process if title object is valid and not special:userlogout
415 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
416 # Gotta hand redirects to special pages differently:
417 # Fill the HTTP response "Location" header and ignore
418 # the rest of the page we're on.
419 global $wgDisableHardRedirects;
420 if( $globalTitle && !$wgDisableHardRedirects ) {
422 if ( $rt->getInterwiki() != '' && $rt->isLocal() ) {
423 $source = $this->mTitle
->getFullURL( 'redirect=no' );
424 $wgOut->redirect( $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ) ) ;
427 if ( $rt->getNamespace() == NS_SPECIAL
) {
428 $wgOut->redirect( $rt->getFullURL() );
432 $redirData = $this->pageDataFromTitle( $dbr, $rt );
434 $redirRev = Revision
::newFromId( $redirData->page_latest
);
435 if( !is_null( $redirRev ) ) {
436 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
439 $this->loadPageData( $data );
440 $revision = $redirRev;
446 # if the title's different from expected, update...
449 if( !$this->mTitle
->equals( $wgTitle ) ) {
450 $wgTitle = $this->mTitle
;
454 # Back to the business at hand...
455 $this->mContent
= $revision->getText();
457 $this->mUser
= $revision->getUser();
458 $this->mUserText
= $revision->getUserText();
459 $this->mComment
= $revision->getComment();
460 $this->mTimestamp
= wfTimestamp( TS_MW
, $revision->getTimestamp() );
462 $this->mRevIdFetched
= $revision->getID();
463 $this->mContentLoaded
= true;
464 $this->mRevision
=& $revision;
466 return $this->mContent
;
470 * Gets the article text without using so many damn globals
471 * Returns false on error
473 * @param integer $oldid
475 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
476 return $this->fetchContent( $oldid, $noredir, false );
480 * Read/write accessor to select FOR UPDATE
482 function forUpdate( $x = NULL ) {
483 return wfSetVar( $this->mForUpdate
, $x );
487 * Get the database which should be used for reads
490 $ret =& wfGetDB( DB_MASTER
);
492 #if ( $this->mForUpdate ) {
493 $ret =& wfGetDB( DB_MASTER
);
495 # $ret =& wfGetDB( DB_SLAVE );
501 * Get options for all SELECT statements
502 * Can pass an option array, to which the class-wide options will be appended
504 function getSelectOptions( $options = '' ) {
505 if ( $this->mForUpdate
) {
506 if ( is_array( $options ) ) {
507 $options[] = 'FOR UPDATE';
509 $options = 'FOR UPDATE';
516 * Return the Article ID
519 if( $this->mTitle
) {
520 return $this->mTitle
->getArticleID();
527 * Returns true if this article exists in the database.
531 return $this->getId() != 0;
535 * Get the view count for this article
537 function getCount() {
538 if ( -1 == $this->mCounter
) {
539 $id = $this->getID();
540 $dbr =& $this->getDB();
541 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
542 'Article::getCount', $this->getSelectOptions() );
544 return $this->mCounter
;
548 * Would the given text make this article a "good" article (i.e.,
549 * suitable for including in the article count)?
550 * @param string $text Text to analyze
551 * @return integer 1 if it can be counted else 0
553 function isCountable( $text ) {
554 global $wgUseCommaCount;
556 if ( NS_MAIN
!= $this->mTitle
->getNamespace() ) { return 0; }
557 if ( $this->isRedirect( $text ) ) { return 0; }
558 $token = ($wgUseCommaCount ?
',' : '[[' );
559 if ( false === strstr( $text, $token ) ) { return 0; }
564 * Tests if the article text represents a redirect
566 function isRedirect( $text = false ) {
567 if ( $text === false ) {
568 $this->loadContent();
569 $titleObj = Title
::newFromRedirect( $this->fetchContent() );
571 $titleObj = Title
::newFromRedirect( $text );
573 return $titleObj !== NULL;
577 * Returns true if the currently-referenced revision is the current edit
578 * to this page (and it exists).
581 function isCurrent() {
582 return $this->exists() &&
583 isset( $this->mRevision
) &&
584 $this->mRevision
->isCurrent();
588 * Loads everything except the text
589 * This isn't necessary for all uses, so it's only done if needed.
592 function loadLastEdit() {
595 if ( -1 != $this->mUser
)
598 # New or non-existent articles have no user information
599 $id = $this->getID();
600 if ( 0 == $id ) return;
602 $this->mLastRevision
= Revision
::loadFromPageId( $this->getDB(), $id );
603 if( !is_null( $this->mLastRevision
) ) {
604 $this->mUser
= $this->mLastRevision
->getUser();
605 $this->mUserText
= $this->mLastRevision
->getUserText();
606 $this->mTimestamp
= $this->mLastRevision
->getTimestamp();
607 $this->mComment
= $this->mLastRevision
->getComment();
608 $this->mMinorEdit
= $this->mLastRevision
->isMinor();
612 function getTimestamp() {
613 $this->loadLastEdit();
614 return wfTimestamp(TS_MW
, $this->mTimestamp
);
618 $this->loadLastEdit();
622 function getUserText() {
623 $this->loadLastEdit();
624 return $this->mUserText
;
627 function getComment() {
628 $this->loadLastEdit();
629 return $this->mComment
;
632 function getMinorEdit() {
633 $this->loadLastEdit();
634 return $this->mMinorEdit
;
637 function getRevIdFetched() {
638 $this->loadLastEdit();
639 return $this->mRevIdFetched
;
642 function getContributors($limit = 0, $offset = 0) {
643 $fname = 'Article::getContributors';
645 # XXX: this is expensive; cache this info somewhere.
647 $title = $this->mTitle
;
649 $dbr =& $this->getDB();
650 $revTable = $dbr->tableName( 'revision' );
651 $userTable = $dbr->tableName( 'user' );
652 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
653 $ns = $title->getNamespace();
654 $user = $this->getUser();
655 $pageId = $this->getId();
657 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
658 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
659 WHERE rev_page = $pageId
660 AND rev_user != $user
661 GROUP BY rev_user, rev_user_text, user_real_name
662 ORDER BY timestamp DESC";
664 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
665 $sql .= ' '. $this->getSelectOptions();
667 $res = $dbr->query($sql, $fname);
669 while ( $line = $dbr->fetchObject( $res ) ) {
670 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
673 $dbr->freeResult($res);
678 * This is the default action of the script: just view the page of
682 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
683 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
684 global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
685 $sk = $wgUser->getSkin();
687 $fname = 'Article::view';
688 wfProfileIn( $fname );
689 # Get variables from query string
690 $oldid = $this->getOldID();
691 $diff = $wgRequest->getVal( 'diff' );
692 $rcid = $wgRequest->getVal( 'rcid' );
693 $rdfrom = $wgRequest->getVal( 'rdfrom' );
695 $wgOut->setArticleFlag( true );
696 $wgOut->setRobotpolicy( 'index,follow' );
697 # If we got diff and oldid in the query, we want to see a
698 # diff page instead of the article.
700 if ( !is_null( $diff ) ) {
701 require_once( 'DifferenceEngine.php' );
702 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
704 $de = new DifferenceEngine( $oldid, $diff, $rcid );
705 // DifferenceEngine directly fetched the revision:
706 $this->mRevIdFetched
= $de->mNewid
;
710 # Run view updates for current revision only
711 $this->viewUpdates();
713 wfProfileOut( $fname );
717 if ( empty( $oldid ) && $this->checkTouched() ) {
718 $wgOut->setETag($wgParserCache->getETag($this, $wgUser));
720 if( $wgOut->checkLastModified( $this->mTouched
) ){
721 wfProfileOut( $fname );
723 } else if ( $this->tryFileCache() ) {
724 # tell wgOut that output is taken care of
726 $this->viewUpdates();
727 wfProfileOut( $fname );
731 # Should the parser cache be used?
732 $pcache = $wgEnableParserCache &&
733 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
736 wfDebug( 'Article::view using parser cache: ' . ($pcache ?
'yes' : 'no' ) . "\n" );
740 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
744 if ( !$outputDone ) {
745 $text = $this->getContent( false ); # May change mTitle by following a redirect
747 # Another whitelist check in case oldid or redirects are altering the title
748 if ( !$this->mTitle
->userCanRead() ) {
749 $wgOut->loginToUse();
754 # We're looking at an old revision
756 if ( !empty( $oldid ) ) {
757 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
758 $wgOut->setRobotpolicy( 'noindex,follow' );
760 if ( '' != $this->mRedirectedFrom
) {
761 $sk = $wgUser->getSkin();
762 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '',
764 $s = wfMsg( 'redirectedfrom', $redir );
765 $wgOut->setSubtitle( $s );
767 # Can't cache redirects
769 } elseif ( !empty( $rdfrom ) ) {
770 global $wgRedirectSources;
771 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
772 $sk = $wgUser->getSkin();
773 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
774 $s = wfMsg( 'redirectedfrom', $redir );
775 $wgOut->setSubtitle( $s );
779 # wrap user css and user js in pre and don't parse
780 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
782 $this->mTitle
->getNamespace() == NS_USER
&&
783 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
785 $wgOut->addWikiText( wfMsg('clearyourcache'));
786 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
787 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
789 $imageUrl = $wgStylePath.'/common/images/redirect.png';
790 $targetUrl = $rt->escapeLocalURL();
791 $titleText = htmlspecialchars( $rt->getPrefixedText() );
792 $link = $sk->makeLinkObj( $rt );
794 $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
795 '<span class="redirectText">'.$link.'</span>' );
797 $parseout = $wgParser->parse($text, $this->mTitle
, ParserOptions
::newFromUser($wgUser));
798 $catlinks = $parseout->getCategoryLinks();
799 $wgOut->addCategoryLinks($catlinks);
800 $skin = $wgUser->getSkin();
801 } else if ( $pcache ) {
802 # Display content and save to parser cache
803 $wgOut->addPrimaryWikiText( $text, $this );
805 # Display content, don't attempt to save to parser cache
807 # Don't show section-edit links on old revisions... this way lies madness.
808 if( !$this->isCurrent() ) {
809 $oldEditSectionSetting = $wgOut->mParserOptions
->setEditSection( false );
811 $wgOut->addWikiText( $text );
813 if( !$this->isCurrent() ) {
814 $wgOut->mParserOptions
->setEditSection( $oldEditSectionSetting );
818 /* title may have been set from the cache */
819 $t = $wgOut->getPageTitle();
821 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
824 # If we have been passed an &rcid= parameter, we want to give the user a
825 # chance to mark this new article as patrolled.
829 && $wgUser->isLoggedIn()
830 && ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
833 "<div class='patrollink'>" .
834 wfMsg ( 'markaspatrolledlink',
835 $sk->makeKnownLinkObj( $this->mTitle
, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
842 if ($wgUseTrackbacks)
843 $this->addTrackbacks();
845 # Put link titles into the link cache
846 $wgOut->transformBuffer();
848 # Add link titles as META keywords
849 $wgOut->addMetaTags() ;
851 $this->viewUpdates();
852 wfProfileOut( $fname );
855 function addTrackbacks() {
856 global $wgOut, $wgUser;
858 $dbr =& wfGetDB(DB_SLAVE
);
860 /* FROM */ 'trackbacks',
861 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
862 /* WHERE */ array('tb_page' => $this->getID())
865 if (!$dbr->numrows($tbs))
869 while ($o = $dbr->fetchObject($tbs)) {
871 if ($wgUser->isSysop()) {
872 $delurl = $this->mTitle
->getFullURL("action=deletetrackback&tbid="
873 . $o->tb_id
. "&token=" . $wgUser->editToken());
874 $rmvtxt = wfMsg('trackbackremove', $delurl);
876 $tbtext .= wfMsg(strlen($o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
883 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
886 function deletetrackback() {
887 global $wgUser, $wgRequest, $wgOut, $wgTitle;
889 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
890 $wgOut->addWikitext(wfMsg('sessionfailure'));
894 if ((!$wgUser->isAllowed('delete'))) {
895 $wgOut->sysopRequired();
900 $wgOut->readOnlyPage();
904 $db =& wfGetDB(DB_MASTER
);
905 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
906 $wgTitle->invalidateCache();
907 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
913 $wgOut->setArticleBodyOnly(true);
918 * Insert a new empty page record for this article.
919 * This *must* be followed up by creating a revision
920 * and running $this->updateToLatest( $rev_id );
921 * or else the record will be left in a funky state.
922 * Best if all done inside a transaction.
924 * @param Database $dbw
925 * @param string $restrictions
926 * @return int The newly created page_id key
929 function insertOn( &$dbw, $restrictions = '' ) {
930 $fname = 'Article::insertOn';
931 wfProfileIn( $fname );
933 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
934 $dbw->insert( 'page', array(
935 'page_id' => $page_id,
936 'page_namespace' => $this->mTitle
->getNamespace(),
937 'page_title' => $this->mTitle
->getDBkey(),
939 'page_restrictions' => $restrictions,
940 'page_is_redirect' => 0, # Will set this shortly...
942 'page_random' => wfRandom(),
943 'page_touched' => $dbw->timestamp(),
944 'page_latest' => 0, # Fill this in shortly...
946 $newid = $dbw->insertId();
948 $this->mTitle
->resetArticleId( $newid );
950 wfProfileOut( $fname );
955 * Update the page record to point to a newly saved revision.
957 * @param Database $dbw
958 * @param Revision $revision -- for ID number, and text used to set
959 length and redirect status fields
960 * @param int $lastRevision -- if given, will not overwrite the page field
961 * when different from the currently set value.
962 * Giving 0 indicates the new page flag should
964 * @return bool true on success, false on failure
967 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
968 $fname = 'Article::updateToRevision';
969 wfProfileIn( $fname );
971 $conditions = array( 'page_id' => $this->getId() );
972 if( !is_null( $lastRevision ) ) {
973 # An extra check against threads stepping on each other
974 $conditions['page_latest'] = $lastRevision;
977 $text = $revision->getText();
978 $dbw->update( 'page',
980 'page_latest' => $revision->getId(),
981 'page_touched' => $dbw->timestamp(),
982 'page_is_new' => ($lastRevision === 0) ?
1 : 0,
983 'page_is_redirect' => Article
::isRedirect( $text ) ?
1 : 0,
984 'page_len' => strlen( $text ),
989 wfProfileOut( $fname );
990 return ( $dbw->affectedRows() != 0 );
994 * If the given revision is newer than the currently set page_latest,
995 * update the page record. Otherwise, do nothing.
997 * @param Database $dbw
998 * @param Revision $revision
1000 function updateIfNewerOn( &$dbw, $revision ) {
1001 $fname = 'Article::updateIfNewerOn';
1002 wfProfileIn( $fname );
1004 $row = $dbw->selectRow(
1005 array( 'revision', 'page' ),
1006 array( 'rev_id', 'rev_timestamp' ),
1008 'page_id' => $this->getId(),
1009 'page_latest=rev_id' ),
1012 if( wfTimestamp(TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
1013 wfProfileOut( $fname );
1016 $prev = $row->rev_id
;
1018 # No or missing previous revision; mark the page as new
1022 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1023 wfProfileOut( $fname );
1028 * Theoretically we could defer these whole insert and update
1029 * functions for after display, but that's taking a big leap
1030 * of faith, and we want to be able to report database
1031 * errors at some point.
1034 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1035 global $wgOut, $wgUser;
1036 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1038 $fname = 'Article::insertNewArticle';
1039 wfProfileIn( $fname );
1041 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1042 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1043 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1044 wfProfileOut( $fname );
1048 $this->mGoodAdjustment
= $this->isCountable( $text );
1049 $this->mTotalAdjustment
= 1;
1051 $ns = $this->mTitle
->getNamespace();
1052 $ttl = $this->mTitle
->getDBkey();
1054 # If this is a comment, add the summary as headline
1055 if($comment && $summary!="") {
1056 $text="== {$summary} ==\n\n".$text;
1058 $text = $this->preSaveTransform( $text );
1059 $isminor = ( $isminor && $wgUser->isLoggedIn() ) ?
1 : 0;
1060 $now = wfTimestampNow();
1062 $dbw =& wfGetDB( DB_MASTER
);
1064 # Add the page record; stake our claim on this title!
1065 $newid = $this->insertOn( $dbw );
1067 # Save the revision text...
1068 $revision = new Revision( array(
1070 'comment' => $summary,
1071 'minor_edit' => $isminor,
1074 $revisionId = $revision->insertOn( $dbw );
1076 $this->mTitle
->resetArticleID( $newid );
1078 # Update the page record with revision data
1079 $this->updateRevisionOn( $dbw, $revision, 0 );
1081 Article
::onArticleCreate( $this->mTitle
);
1083 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary, 'default',
1084 '', strlen( $text ), $revisionId );
1088 if(!$this->mTitle
->userIsWatching()) $this->watch();
1090 if ( $this->mTitle
->userIsWatching() ) {
1095 # The talk page isn't in the regular link tables, so we need to update manually:
1096 $talkns = $ns ^
1; # talk -> normal; normal -> talk
1097 $dbw->update( 'page',
1098 array( 'page_touched' => $dbw->timestamp($now) ),
1099 array( 'page_namespace' => $talkns,
1100 'page_title' => $ttl ),
1103 # standard deferred updates
1104 $this->editUpdates( $text, $summary, $isminor, $now );
1106 $oldid = 0; # new article
1107 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1109 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1111 $watchthis, NULL ) );
1112 wfProfileOut( $fname );
1115 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1116 $this->replaceSection( $section, $text, $summary, $edittime );
1119 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1120 $fname = 'Article::replaceSection';
1121 wfProfileIn( $fname );
1123 if ($section != '') {
1124 if( is_null( $edittime ) ) {
1125 $rev = Revision
::newFromTitle( $this->mTitle
);
1127 $dbw =& wfGetDB( DB_MASTER
);
1128 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
1130 $oldtext = $rev->getText();
1132 if($section=='new') {
1133 if($summary) $subject="== {$summary} ==\n\n";
1134 $text=$oldtext."\n\n".$subject.$text;
1137 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1138 # comments to be stripped as well)
1139 $striparray=array();
1140 $parser=new Parser();
1141 $parser->mOutputType
=OT_WIKI
;
1142 $parser->mOptions
= new ParserOptions();
1143 $oldtext=$parser->strip($oldtext, $striparray, true);
1145 # now that we can be sure that no pseudo-sections are in the source,
1147 # Unfortunately we can't simply do a preg_replace because that might
1148 # replace the wrong section, so we have to use the section counter instead
1149 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
1150 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
1151 $secs[$section*2]=$text."\n\n"; // replace with edited
1153 # section 0 is top (intro) section
1156 # headline of old section - we need to go through this section
1157 # to determine if there are any subsections that now need to
1158 # be erased, as the mother section has been replaced with
1159 # the text of all subsections.
1160 $headline=$secs[$section*2-1];
1161 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
1162 $hlevel=$matches[1];
1164 # determine headline level for wikimarkup headings
1165 if(strpos($hlevel,'=')!==false) {
1166 $hlevel=strlen($hlevel);
1169 $secs[$section*2-1]=''; // erase old headline
1172 while(!empty($secs[$count*2-1]) && !$break) {
1174 $subheadline=$secs[$count*2-1];
1176 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
1177 $subhlevel=$matches[1];
1178 if(strpos($subhlevel,'=')!==false) {
1179 $subhlevel=strlen($subhlevel);
1181 if($subhlevel > $hlevel) {
1182 // erase old subsections
1183 $secs[$count*2-1]='';
1186 if($subhlevel <= $hlevel) {
1194 $text=join('',$secs);
1195 # reinsert the stuff that we stripped out earlier
1196 $text=$parser->unstrip($text,$striparray);
1197 $text=$parser->unstripNoWiki($text,$striparray);
1201 wfProfileOut( $fname );
1206 * Change an existing article. Puts the previous version back into the old table, updates RC
1207 * and all necessary caches, mostly via the deferred update array.
1209 * It is possible to call this function from a command-line script, but note that you should
1210 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1212 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1213 global $wgOut, $wgUser;
1214 global $wgDBtransactions, $wgMwRedir;
1215 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
1217 $fname = 'Article::updateArticle';
1218 wfProfileIn( $fname );
1221 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1223 &$watchthis, &$sectionanchor ) ) ) {
1224 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1225 wfProfileOut( $fname );
1229 $isminor = ( $minor && $wgUser->isLoggedIn() );
1230 if ( $this->isRedirect( $text ) ) {
1231 # Remove all content but redirect
1232 # This could be done by reconstructing the redirect from a title given by
1233 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
1235 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1237 $text = $m[1] . "\n";
1240 else { $redir = 0; }
1242 $text = $this->preSaveTransform( $text );
1243 $dbw =& wfGetDB( DB_MASTER
);
1244 $now = wfTimestampNow();
1246 # Update article, but only if changed.
1248 # It's important that we either rollback or complete, otherwise an attacker could
1249 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1250 # could conceivably have the same effect, especially if cur is locked for long periods.
1251 if( !$wgDBtransactions ) {
1252 $userAbort = ignore_user_abort( true );
1255 $oldtext = $this->getContent( true );
1256 $oldsize = strlen( $oldtext );
1257 $newsize = strlen( $text );
1260 if ( 0 != strcmp( $text, $oldtext ) ) {
1261 $this->mGoodAdjustment
= $this->isCountable( $text )
1262 - $this->isCountable( $oldtext );
1263 $this->mTotalAdjustment
= 0;
1264 $now = wfTimestampNow();
1266 $lastRevision = $dbw->selectField(
1267 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1269 $revision = new Revision( array(
1270 'page' => $this->getId(),
1271 'comment' => $summary,
1272 'minor_edit' => $isminor,
1276 $dbw->immediateCommit();
1278 $revisionId = $revision->insertOn( $dbw );
1281 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1284 /* Belated edit conflict! Run away!! */
1288 # Update recentchanges and purge cache and whatnot
1289 $bot = (int)($wgUser->isBot() ||
$forceBot);
1290 RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $wgUser, $summary,
1291 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1293 Article
::onArticleEdit( $this->mTitle
);
1298 if( !$wgDBtransactions ) {
1299 ignore_user_abort( $userAbort );
1304 if (!$this->mTitle
->userIsWatching()) {
1305 $dbw->immediateCommit();
1311 if ( $this->mTitle
->userIsWatching() ) {
1312 $dbw->immediateCommit();
1318 # standard deferred updates
1319 $this->editUpdates( $text, $summary, $minor, $now );
1323 # Template namespace
1324 # Purge all articles linking here
1325 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1326 $titles = $this->mTitle
->getLinksTo();
1327 Title
::touchArray( $titles );
1328 if ( $wgUseSquid ) {
1329 foreach ( $titles as $title ) {
1330 $urls[] = $title->getInternalURL();
1336 if ( $wgUseSquid ) {
1337 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1338 $u = new SquidUpdate( $urls );
1339 array_push( $wgPostCommitUpdateList, $u );
1343 if ( $wgUseFileCache ) {
1344 $cm = new CacheManager($this->mTitle
);
1345 @unlink
($cm->fileCacheName());
1348 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1350 wfRunHooks( 'ArticleSaveComplete',
1351 array( &$this, &$wgUser, $text,
1353 $watchthis, $sectionanchor ) );
1354 wfProfileOut( $fname );
1359 * After we've either updated or inserted the article, update
1360 * the link tables and redirect to the new page.
1362 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1363 global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1364 global $wgUseEnotif;
1366 $fname = 'Article::showArticle';
1367 wfProfileIn( $fname );
1369 $wgLinkCache = new LinkCache();
1371 if ( !$wgUseDumbLinkUpdate ) {
1372 # Preload links to reduce lock time
1373 if ( $wgAntiLockFlags & ALF_PRELOAD_LINKS
) {
1374 $wgLinkCache->preFill( $this->mTitle
);
1375 $wgLinkCache->clear();
1379 # Parse the text and replace links with placeholders
1380 $wgOut = new OutputPage();
1382 # Pass the current title along in case we're creating a wiki page
1383 # which is different than the currently displayed one (e.g. image
1384 # pages created on file uploads); otherwise, link updates will
1386 $wgOut->addWikiTextWithTitle( $text, $this->mTitle
);
1388 if ( !$wgUseDumbLinkUpdate ) {
1389 # Move the current links back to the second register
1390 $wgLinkCache->swapRegisters();
1392 # Get old version of link table to allow incremental link updates
1393 # Lock this data now since it is needed for an update
1394 $wgLinkCache->forUpdate( true );
1395 $wgLinkCache->preFill( $this->mTitle
);
1397 # Swap this old version back into its rightful place
1398 $wgLinkCache->swapRegisters();
1401 if( $this->isRedirect( $text ) )
1405 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1407 if ( $wgUseEnotif ) {
1408 # this would be better as an extension hook
1409 include_once( "UserMailer.php" );
1410 $wgEnotif = new EmailNotification ();
1411 $wgEnotif->notifyOnPageChange( $this->mTitle
, $now, $summary, $me2, $oldid );
1413 wfProfileOut( $fname );
1417 * Mark this particular edit as patrolled
1419 function markpatrolled() {
1420 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1421 $wgOut->setRobotpolicy( 'noindex,follow' );
1423 if ( !$wgUseRCPatrol )
1425 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1428 if ( $wgUser->isAnon() )
1430 $wgOut->loginToUse();
1433 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1435 $wgOut->sysopRequired();
1438 $rcid = $wgRequest->getVal( 'rcid' );
1439 if ( !is_null ( $rcid ) )
1441 RecentChange
::markPatrolled( $rcid );
1442 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1443 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1445 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1446 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1450 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1457 function validate() {
1458 global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
1460 if ( !$wgUseValidation ) # Are we using article validation at all?
1462 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
1466 $wgOut->setRobotpolicy( 'noindex,follow' );
1467 $revision = $wgRequest->getVal( 'revision' );
1469 include_once ( "SpecialValidate.php" ) ; # The "Validation" class
1471 $v = new Validation
;
1472 if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
1473 $t = $v->showList ( $this ) ;
1474 else if ( $wgRequest->getVal ( "mode" , "" ) == "details" )
1475 $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ;
1477 $t = $v->validatePageForm ( $this , $revision ) ;
1479 $wgOut->addHTML ( $t ) ;
1483 * Add this page to $wgUser's watchlist
1488 global $wgUser, $wgOut;
1490 if ( $wgUser->isAnon() ) {
1491 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1494 if ( wfReadOnly() ) {
1495 $wgOut->readOnlyPage();
1499 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1501 $wgUser->addWatch( $this->mTitle
);
1502 $wgUser->saveSettings();
1504 wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1506 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1507 $wgOut->setRobotpolicy( 'noindex,follow' );
1509 $link = $this->mTitle
->getPrefixedText();
1510 $text = wfMsg( 'addedwatchtext', $link );
1511 $wgOut->addWikiText( $text );
1514 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1518 * Stop watching a page
1521 function unwatch() {
1523 global $wgUser, $wgOut;
1525 if ( $wgUser->isAnon() ) {
1526 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1529 if ( wfReadOnly() ) {
1530 $wgOut->readOnlyPage();
1534 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1536 $wgUser->removeWatch( $this->mTitle
);
1537 $wgUser->saveSettings();
1539 wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1541 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1542 $wgOut->setRobotpolicy( 'noindex,follow' );
1544 $link = $this->mTitle
->getPrefixedText();
1545 $text = wfMsg( 'removedwatchtext', $link );
1546 $wgOut->addWikiText( $text );
1549 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1555 function protect( $limit = 'sysop' ) {
1556 global $wgUser, $wgOut, $wgRequest;
1558 if ( ! $wgUser->isAllowed('protect') ) {
1559 $wgOut->sysopRequired();
1562 if ( wfReadOnly() ) {
1563 $wgOut->readOnlyPage();
1566 $id = $this->mTitle
->getArticleID();
1568 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1572 $confirm = $wgRequest->wasPosted() &&
1573 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1574 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1575 $reason = $wgRequest->getText( 'wpReasonProtect' );
1578 $dbw =& wfGetDB( DB_MASTER
);
1579 $dbw->update( 'page',
1581 'page_touched' => $dbw->timestamp(),
1582 'page_restrictions' => (string)$limit
1583 ), array( /* WHERE */
1585 ), 'Article::protect'
1588 $restrictions = "move=" . $limit;
1590 $restrictions .= ":edit=" . $limit;
1592 if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly))) {
1594 $dbw =& wfGetDB( DB_MASTER
);
1595 $dbw->update( 'page',
1597 'page_touched' => $dbw->timestamp(),
1598 'page_restrictions' => $restrictions
1599 ), array( /* WHERE */
1601 ), 'Article::protect'
1604 wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit == 'sysop', $reason, $moveonly));
1606 $log = new LogPage( 'protect' );
1607 if ( $limit === '' ) {
1608 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1610 $log->addEntry( 'protect', $this->mTitle
, $reason );
1612 $wgOut->redirect( $this->mTitle
->getFullURL() );
1616 return $this->confirmProtect( '', '', $limit );
1621 * Output protection confirmation dialog
1623 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1624 global $wgOut, $wgUser;
1626 wfDebug( "Article::confirmProtect\n" );
1628 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1629 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1635 if ( $limit === '' ) {
1636 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1637 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1638 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1639 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1640 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1642 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1643 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1644 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1645 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1646 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1647 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1650 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1651 $token = htmlspecialchars( $wgUser->editToken() );
1654 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1658 <label for='wpReasonProtect'>{$protcom}:</label>
1661 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1664 if($moveonly != '') {
1668 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1671 <label for='wpMoveOnly'>{$moveonly}</label>
1679 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1683 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1686 $wgOut->returnToMain( false );
1690 * Unprotect the pages
1692 function unprotect() {
1693 return $this->protect( '' );
1697 * UI entry point for page deletion
1700 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1701 $fname = 'Article::delete';
1702 $confirm = $wgRequest->wasPosted() &&
1703 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1704 $reason = $wgRequest->getText( 'wpReason' );
1706 # This code desperately needs to be totally rewritten
1709 if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
1710 $wgOut->sysopRequired();
1713 if( wfReadOnly() ) {
1714 $wgOut->readOnlyPage();
1718 # Better double-check that it hasn't been deleted yet!
1719 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1720 if( !$this->mTitle
->exists() ) {
1721 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1726 $this->doDelete( $reason );
1730 # determine whether this page has earlier revisions
1731 # and insert a warning if it does
1732 # we select the text because it might be useful below
1733 $dbr =& $this->getDB();
1734 $ns = $this->mTitle
->getNamespace();
1735 $title = $this->mTitle
->getDBkey();
1736 $revisions = $dbr->select( array( 'page', 'revision' ),
1737 array( 'rev_id', 'rev_user_text' ),
1739 'page_namespace' => $ns,
1740 'page_title' => $title,
1741 'rev_page = page_id'
1742 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) )
1745 if( $dbr->numRows( $revisions ) > 1 && !$confirm ) {
1746 $skin=$wgUser->getSkin();
1747 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1748 $wgOut->addHTML( $skin->historyLink() .'</b>');
1752 $rev = Revision
::newFromTitle( $this->mTitle
);
1754 # Fetch name(s) of contributors
1756 $all_same_user = true;
1757 while( $row = $dbr->fetchObject( $revisions ) ) {
1758 if( $rev_name != '' && $rev_name != $row->rev_user_text
) {
1759 $all_same_user = false;
1761 $rev_name = $row->rev_user_text
;
1765 if( !is_null( $rev ) ) {
1766 # if this is a mini-text, we can paste part of it into the deletion reason
1767 $text = $rev->getText();
1769 #if this is empty, an earlier revision may contain "useful" text
1772 $prev = $rev->getPrevious();
1774 $text = $prev->getText();
1779 $length = strlen( $text );
1781 # this should not happen, since it is not possible to store an empty, new
1782 # page. Let's insert a standard text in case it does, though
1783 if( $length == 0 && $reason === '' ) {
1784 $reason = wfMsgForContent( 'exblank' );
1787 if( $length < 500 && $reason === '' ) {
1788 # comment field=255, let's grep the first 150 to have some user
1791 $text = $wgContLang->truncate( $text, 150, '...' );
1793 # let's strip out newlines
1794 $text = preg_replace( "/[\n\r]/", '', $text );
1797 if( !$all_same_user ) {
1798 $reason = wfMsgForContent( 'excontent', $text );
1800 $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
1803 $reason = wfMsgForContent( 'exbeforeblank', $text );
1808 return $this->confirmDelete( '', $reason );
1812 * Output deletion confirmation dialog
1814 function confirmDelete( $par, $reason ) {
1815 global $wgOut, $wgUser;
1817 wfDebug( "Article::confirmDelete\n" );
1819 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1820 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1821 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1822 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1824 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1826 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1827 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1828 $token = htmlspecialchars( $wgUser->editToken() );
1831 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1835 <label for='wpReason'>{$delcom}:</label>
1838 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1844 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1848 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1851 $wgOut->returnToMain( false );
1856 * Perform a deletion and output success or failure messages
1858 function doDelete( $reason ) {
1859 global $wgOut, $wgUser, $wgContLang;
1860 $fname = 'Article::doDelete';
1861 wfDebug( $fname."\n" );
1863 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1864 if ( $this->doDeleteArticle( $reason ) ) {
1865 $deleted = $this->mTitle
->getPrefixedText();
1867 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1868 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1870 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1871 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1873 $wgOut->addWikiText( $text );
1874 $wgOut->returnToMain( false );
1875 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1877 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1883 * Back-end article deletion
1884 * Deletes the article with database consistency, writes logs, purges caches
1887 function doDeleteArticle( $reason ) {
1889 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
1890 global $wgUseTrackbacks;
1892 $fname = 'Article::doDeleteArticle';
1893 wfDebug( $fname."\n" );
1895 $dbw =& wfGetDB( DB_MASTER
);
1896 $ns = $this->mTitle
->getNamespace();
1897 $t = $this->mTitle
->getDBkey();
1898 $id = $this->mTitle
->getArticleID();
1900 if ( $t == '' ||
$id == 0 ) {
1904 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
1905 array_push( $wgDeferredUpdateList, $u );
1907 $linksTo = $this->mTitle
->getLinksTo();
1910 if ( $wgUseSquid ) {
1912 $this->mTitle
->getInternalURL(),
1913 $this->mTitle
->getInternalURL( 'history' )
1916 $u = SquidUpdate
::newFromTitles( $linksTo, $urls );
1917 array_push( $wgPostCommitUpdateList, $u );
1921 # Client and file cache invalidation
1922 Title
::touchArray( $linksTo );
1925 // For now, shunt the revision data into the archive table.
1926 // Text is *not* removed from the text table; bulk storage
1927 // is left intact to avoid breaking block-compression or
1928 // immutable storage schemes.
1930 // For backwards compatibility, note that some older archive
1931 // table entries will have ar_text and ar_flags fields still.
1933 // In the future, we may keep revisions and mark them with
1934 // the rev_deleted field, which is reserved for this purpose.
1935 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1937 'ar_namespace' => 'page_namespace',
1938 'ar_title' => 'page_title',
1939 'ar_comment' => 'rev_comment',
1940 'ar_user' => 'rev_user',
1941 'ar_user_text' => 'rev_user_text',
1942 'ar_timestamp' => 'rev_timestamp',
1943 'ar_minor_edit' => 'rev_minor_edit',
1944 'ar_rev_id' => 'rev_id',
1945 'ar_text_id' => 'rev_text_id',
1948 'page_id = rev_page'
1952 # Now that it's safely backed up, delete it
1953 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
1954 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
1956 if ($wgUseTrackbacks)
1957 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
1959 # Clean up recentchanges entries...
1960 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1962 # Finally, clean up the link tables
1963 $t = $this->mTitle
->getPrefixedDBkey();
1965 Article
::onArticleDelete( $this->mTitle
);
1967 # Delete outgoing links
1968 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1969 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1970 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1973 $log = new LogPage( 'delete' );
1974 $log->addEntry( 'delete', $this->mTitle
, $reason );
1976 # Clear the cached article id so the interface doesn't act like we exist
1977 $this->mTitle
->resetArticleID( 0 );
1978 $this->mTitle
->mArticleID
= 0;
1983 * Revert a modification
1985 function rollback() {
1986 global $wgUser, $wgOut, $wgRequest;
1987 $fname = 'Article::rollback';
1989 if ( ! $wgUser->isAllowed('rollback') ) {
1990 $wgOut->sysopRequired();
1993 if ( wfReadOnly() ) {
1994 $wgOut->readOnlyPage( $this->getContent( true ) );
1997 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
1998 array( $this->mTitle
->getPrefixedText(),
1999 $wgRequest->getVal( 'from' ) ) ) ) {
2000 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2001 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2004 $dbw =& wfGetDB( DB_MASTER
);
2006 # Enhanced rollback, marks edits rc_bot=1
2007 $bot = $wgRequest->getBool( 'bot' );
2009 # Replace all this user's current edits with the next one down
2010 $tt = $this->mTitle
->getDBKey();
2011 $n = $this->mTitle
->getNamespace();
2013 # Get the last editor, lock table exclusively
2015 $current = Revision
::newFromTitle( $this->mTitle
);
2016 if( is_null( $current ) ) {
2017 # Something wrong... no page?
2019 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2023 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2024 if( $from != $current->getUserText() ) {
2025 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2026 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2027 htmlspecialchars( $this->mTitle
->getPrefixedText()),
2028 htmlspecialchars( $from ),
2029 htmlspecialchars( $current->getUserText() ) ) );
2030 if( $current->getComment() != '') {
2032 wfMsg( 'editcomment',
2033 htmlspecialchars( $current->getComment() ) ) );
2038 # Get the last edit not by this guy
2039 $user = intval( $current->getUser() );
2040 $user_text = $dbw->addQuotes( $current->getUserText() );
2041 $s = $dbw->selectRow( 'revision',
2042 array( 'rev_id', 'rev_timestamp' ),
2044 'rev_page' => $current->getPage(),
2045 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2048 'USE INDEX' => 'page_timestamp',
2049 'ORDER BY' => 'rev_timestamp DESC' )
2051 if( $s === false ) {
2054 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2055 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2060 # Mark all reverted edits as bot
2061 $dbw->update( 'recentchanges',
2064 ), array( /* WHERE */
2065 'rc_cur_id' => $current->getPage(),
2066 'rc_user_text' => $current->getUserText(),
2067 "rc_timestamp > '{$s->rev_timestamp}'",
2073 $target = Revision
::newFromId( $s->rev_id
);
2074 $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2076 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2077 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2078 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
2080 $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
2081 Article
::onArticleEdit( $this->mTitle
);
2084 $wgOut->returnToMain( false );
2089 * Do standard deferred updates after page view
2092 function viewUpdates() {
2093 global $wgDeferredUpdateList, $wgUseEnotif;
2095 if ( 0 != $this->getID() ) {
2096 global $wgDisableCounters;
2097 if( !$wgDisableCounters ) {
2098 Article
::incViewCount( $this->getID() );
2099 $u = new SiteStatsUpdate( 1, 0, 0 );
2100 array_push( $wgDeferredUpdateList, $u );
2104 # Update newtalk status if user is reading their own
2108 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
2109 $this->mTitle
->getText() == $wgUser->getName())
2111 if ( $wgUseEnotif ) {
2112 require_once( 'UserTalkUpdate.php' );
2113 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
2115 $wgUser->setNewtalk(0);
2116 $wgUser->saveNewtalk();
2118 } elseif ( $wgUseEnotif ) {
2119 $wgUser->clearNotification( $this->mTitle
);
2125 * Do standard deferred updates after page edit.
2126 * Every 1000th edit, prune the recent changes table.
2128 * @param string $text
2130 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
2131 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
2132 global $wgMessageCache, $wgUser, $wgUseEnotif;
2135 if ( 0 == mt_rand( 0, 999 ) ) {
2136 # Periodically flush old entries from the recentchanges table.
2138 $dbw =& wfGetDB( DB_MASTER
);
2139 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2140 $recentchanges = $dbw->tableName( 'recentchanges' );
2141 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2142 //$dbw->query( $sql ); // HACK: disabled for now, slowness
2144 // re-enabled for commit of unrelated live changes -- TS
2145 $dbw->query( $sql );
2147 $id = $this->getID();
2148 $title = $this->mTitle
->getPrefixedDBkey();
2149 $shortTitle = $this->mTitle
->getDBkey();
2152 $u = new LinksUpdate( $id, $title );
2153 array_push( $wgDeferredUpdateList, $u );
2154 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment
, $this->mTotalAdjustment
);
2155 array_push( $wgDeferredUpdateList, $u );
2156 $u = new SearchUpdate( $id, $title, $text );
2157 array_push( $wgDeferredUpdateList, $u );
2159 # If this is another user's talk page, update newtalk
2161 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&& $shortTitle != $wgUser->getName()) {
2162 if ( $wgUseEnotif ) {
2163 require_once( 'UserTalkUpdate.php' );
2164 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary,
2165 $minoredit, $timestamp_of_pagechange);
2167 $other = User
::newFromName( $shortTitle );
2168 if( is_null( $other ) && User
::isIP( $shortTitle ) ) {
2169 // An anonymous user
2170 $other = new User();
2171 $other->setName( $shortTitle );
2174 $other->setNewtalk(1);
2175 $other->saveNewtalk();
2180 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2181 $wgMessageCache->replace( $shortTitle, $text );
2187 * @todo document this function
2189 * @param string $oldid Revision ID of this article revision
2191 function setOldSubtitle( $oldid=0 ) {
2192 global $wgLang, $wgOut, $wgUser;
2194 $current = ( $oldid == $this->mLatest
);
2195 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
2196 $sk = $wgUser->getSkin();
2198 ?
wfMsg( 'currentrevisionlink' )
2199 : $lnk = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
2200 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
2201 $nextlink = $current
2202 ?
wfMsg( 'nextrevision' )
2203 : $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2204 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2205 $wgOut->setSubtitle( $r );
2209 * This function is called right before saving the wikitext,
2210 * so we can do things like signatures and links-in-context.
2212 * @param string $text
2214 function preSaveTransform( $text ) {
2215 global $wgParser, $wgUser;
2216 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
2219 /* Caching functions */
2222 * checkLastModified returns true if it has taken care of all
2223 * output to the client that is necessary for this request.
2224 * (that is, it has sent a cached version of the page)
2226 function tryFileCache() {
2227 static $called = false;
2229 wfDebug( " tryFileCache() -- called twice!?\n" );
2233 if($this->isFileCacheable()) {
2234 $touched = $this->mTouched
;
2235 $cache = new CacheManager( $this->mTitle
);
2236 if($cache->isFileCacheGood( $touched )) {
2238 wfDebug( " tryFileCache() - about to load\n" );
2239 $cache->loadFromFileCache();
2242 wfDebug( " tryFileCache() - starting buffer\n" );
2243 ob_start( array(&$cache, 'saveToFileCache' ) );
2246 wfDebug( " tryFileCache() - not cacheable\n" );
2251 * Check if the page can be cached
2254 function isFileCacheable() {
2255 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2256 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2258 return $wgUseFileCache
2259 and (!$wgShowIPinHeader)
2260 and ($this->getID() != 0)
2261 and ($wgUser->isAnon())
2262 and (!$wgUser->getNewtalk())
2263 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2264 and (empty( $action ) ||
$action == 'view')
2265 and (!isset($oldid))
2267 and (!isset($redirect))
2268 and (!isset($printable))
2269 and (!$this->mRedirectedFrom
);
2273 * Loads cur_touched and returns a value indicating if it should be used
2276 function checkTouched() {
2277 $fname = 'Article::checkTouched';
2278 if( !$this->mDataLoaded
) {
2279 $dbr =& $this->getDB();
2280 $data = $this->pageDataFromId( $dbr, $this->getId() );
2282 $this->loadPageData( $data );
2285 return !$this->mIsRedirect
;
2289 * Edit an article without doing all that other stuff
2290 * The article must already exist; link tables etc
2291 * are not updated, caches are not flushed.
2293 * @param string $text text submitted
2294 * @param string $comment comment submitted
2295 * @param bool $minor whereas it's a minor modification
2297 function quickEdit( $text, $comment = '', $minor = 0 ) {
2298 $fname = 'Article::quickEdit';
2299 wfProfileIn( $fname );
2301 $dbw =& wfGetDB( DB_MASTER
);
2303 $revision = new Revision( array(
2304 'page' => $this->getId(),
2306 'comment' => $comment,
2307 'minor_edit' => $minor ?
1 : 0,
2309 $revisionId = $revision->insertOn( $dbw );
2310 $this->updateRevisionOn( $dbw, $revision );
2313 wfProfileOut( $fname );
2317 * Used to increment the view counter
2320 * @param integer $id article id
2322 function incViewCount( $id ) {
2323 $id = intval( $id );
2324 global $wgHitcounterUpdateFreq;
2326 $dbw =& wfGetDB( DB_MASTER
);
2327 $pageTable = $dbw->tableName( 'page' );
2328 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2329 $acchitsTable = $dbw->tableName( 'acchits' );
2331 if( $wgHitcounterUpdateFreq <= 1 ){ //
2332 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2336 # Not important enough to warrant an error page in case of failure
2337 $oldignore = $dbw->ignoreErrors( true );
2339 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2341 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2342 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2343 # Most of the time (or on SQL errors), skip row count check
2344 $dbw->ignoreErrors( $oldignore );
2348 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2349 $row = $dbw->fetchObject( $res );
2350 $rown = intval( $row->n
);
2351 if( $rown >= $wgHitcounterUpdateFreq ){
2352 wfProfileIn( 'Article::incViewCount-collect' );
2353 $old_user_abort = ignore_user_abort( true );
2355 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2356 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2357 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2359 $dbw->query("DELETE FROM $hitcounterTable");
2360 $dbw->query('UNLOCK TABLES');
2361 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2362 'WHERE page_id = hc_id');
2363 $dbw->query("DROP TABLE $acchitsTable");
2365 ignore_user_abort( $old_user_abort );
2366 wfProfileOut( 'Article::incViewCount-collect' );
2368 $dbw->ignoreErrors( $oldignore );
2372 * The onArticle*() functions are supposed to be a kind of hooks
2373 * which should be called whenever any of the specified actions
2376 * This is a good place to put code to clear caches, for instance.
2378 * This is called on page move and undelete, as well as edit
2380 * @param $title_obj a title object
2383 function onArticleCreate($title_obj) {
2384 global $wgUseSquid, $wgPostCommitUpdateList;
2386 $title_obj->touchLinks();
2387 $titles = $title_obj->getLinksTo();
2390 if ( $wgUseSquid ) {
2391 $urls = $title_obj->getSquidURLs();
2392 foreach ( $titles as $linkTitle ) {
2393 $urls[] = $linkTitle->getInternalURL();
2395 $u = new SquidUpdate( $urls );
2396 array_push( $wgPostCommitUpdateList, $u );
2400 function onArticleDelete( $title ) {
2401 global $wgMessageCache;
2403 $title->touchLinks();
2405 if( $title->getNamespace() == NS_MEDIAWIKI
) {
2406 $wgMessageCache->replace( $title->getDBkey(), false );
2410 function onArticleEdit($title_obj) {
2411 // This would be an appropriate place to purge caches.
2412 // Why's this not in here now?
2418 * Info about this page
2419 * Called for ?action=info when $wgAllowPageInfo is on.
2424 global $wgLang, $wgOut, $wgAllowPageInfo;
2425 $fname = 'Article::info';
2427 if ( !$wgAllowPageInfo ) {
2428 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2432 $page = $this->mTitle
->getSubjectPage();
2434 $wgOut->setPagetitle( $page->getPrefixedText() );
2435 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2437 # first, see if the page exists at all.
2438 $exists = $page->getArticleId() != 0;
2440 $wgOut->addHTML( wfMsg('noarticletext') );
2442 $dbr =& $this->getDB( DB_SLAVE
);
2444 'wl_title' => $page->getDBkey(),
2445 'wl_namespace' => $page->getNamespace() );
2446 $numwatchers = $dbr->selectField(
2451 $this->getSelectOptions() );
2453 $pageInfo = $this->pageCountInfo( $page );
2454 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2456 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2457 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2459 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2461 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2463 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2465 $wgOut->addHTML( '</ul>' );
2471 * Return the total number of edits and number of unique editors
2472 * on a given page. If page does not exist, returns false.
2474 * @param Title $title
2478 function pageCountInfo( $title ) {
2479 $id = $title->getArticleId();
2484 $dbr =& $this->getDB( DB_SLAVE
);
2486 $rev_clause = array( 'rev_page' => $id );
2487 $fname = 'Article::pageCountInfo';
2489 $edits = $dbr->selectField(
2494 $this->getSelectOptions() );
2496 $authors = $dbr->selectField(
2498 'COUNT(DISTINCT rev_user_text)',
2501 $this->getSelectOptions() );
2503 return array( 'edits' => $edits, 'authors' => $authors );
2507 * Return a list of templates used by this article.
2508 * Uses the links table to find the templates
2512 function getUsedTemplates() {
2514 $id = $this->mTitle
->getArticleID();
2516 $db =& wfGetDB( DB_SLAVE
);
2517 $res = $db->select( array( 'pagelinks' ),
2518 array( 'pl_title' ),
2521 'pl_namespace' => NS_TEMPLATE
),
2522 'Article:getUsedTemplates' );
2523 if ( false !== $res ) {
2524 if ( $db->numRows( $res ) ) {
2525 while ( $row = $db->fetchObject( $res ) ) {
2526 $result[] = $row->pl_title
;
2530 $db->freeResult( $res );